from tools import *
import sys
import datetime
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
import json
import time
import os
import cv2
import numpy as np
import shutil
import ctypes


# 线程
class Schedule_Thread(QThread):
    # 创建自定义信号
    get_re_time_signal = pyqtSignal(str)  # 修改重复设置窗口的时间
    get_re_week_signal = pyqtSignal(str)  # 修改周重复提醒

    def __init__(self):
        super().__init__()

        # 创建窗口
        self.w_re_1 = re_window_1()  # 小窗口
        self.w_re_2 = re_window_2()  # 大窗口

        self.is_show_1 = 0
        self.is_show_2 = 0

        self.re_time = "12:00"
        self.re_week = "163"

        self.w_re_1.close_signal.connect(self.change_is_show)
        self.w_re_2.close_signal.connect(self.change_is_show)

    """打开和关闭窗口函数"""

    # 打开重复窗口
    def open_re_window(self, s):
        if s.split(",")[0] == "1":
            if self.is_show_1 == 0:
                self.get_re_time_signal.emit("")
                self.w_re_2.close()
                time = QTime(int(self.re_time.split(":")[0]), int(self.re_time.split(":")[1]))
                self.w_re_1.time_edit.setTime(time)
                self.w_re_1.move(int(s.split(",")[1]), int(s.split(",")[2]))
                self.w_re_1.show()
                self.is_show_1 = 1
            else:
                self.w_re_1.close()
                self.is_show_1 = 0
        else:
            if self.is_show_2 == 0:
                self.get_re_time_signal.emit("")
                self.get_re_week_signal.emit("")
                self.w_re_1.close()
                time = QTime(int(self.re_time.split(":")[0]), int(self.re_time.split(":")[1]))
                self.w_re_2.time_edit.setTime(time)
                self.w_re_2.set_checkbox(self.re_week)
                self.w_re_2.move(int(s.split(",")[1]), int(s.split(",")[2]))
                self.w_re_2.show()
                self.is_show_2 = 1
            else:
                self.w_re_2.close()
                self.is_show_2 = 0

    # 关闭设置界面
    def close_window(self):
        self.w_re_1.close()
        self.w_re_2.close()
        self.is_show_1 = 0
        self.is_show_2 = 0

    # 确定按钮点击后关闭窗口
    def change_is_show(self):
        self.is_show_1 = 0
        self.is_show_2 = 0

    # 查看图片
    def check_img(self, s):

        import tkinter as tk

        def GetScreenCenter():
            root = tk.Tk()
            return root.winfo_screenwidth() // 2, root.winfo_screenheight() // 2

        src = cv2.imdecode(np.fromfile(s, dtype=np.uint8), -1)
        center_x, center_y = GetScreenCenter()
        img_h, img_w, _ = src.shape
        t_x, t_y = (center_x - img_w // 2), (center_y - img_h // 2)
        cv2.namedWindow("show_image", cv2.WINDOW_AUTOSIZE)
        cv2.moveWindow("show_image", t_x, t_y)
        cv2.imshow("show_image", src)
        cv2.waitKey(0)

    # 播放视频

    def play_video(self, s):
        import subprocess
        path = os.path.abspath(s)

        subprocess.call(r'C:\Program Files\Windows Media Player\wmplayer.exe "%s"' % path)

    # 处理业务逻辑
    def run(self):
        while 1:
            time.sleep(1)


# 设置窗口
class Settingwindow(QWidget):
    change_backgruond_signal = pyqtSignal(str)
    change_teaching_week_address_signal = pyqtSignal(str)

    def __init__(self):
        super().__init__()
        self.address = read_setting("地址")
        self.background_img = read_setting("背景")
        self.init_ui()

    # 初始化ui函数
    def init_ui(self):
        self.resize(400, 410)  # 设置窗口大小
        self.setFixedSize(400, 410)  # 固定大小
        self.setWindowFlags(Qt.FramelessWindowHint)  # 去边框化
        self.setWindowIcon(QIcon("../static/img/logo1.png"))

        ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID("myappid")

        self.set_action_bar()

        self.set_labels()

        self.set_img()

        self.set_teaching_edit()

        self.set_weather_address()

    # 设置操作按钮
    def set_action_bar(self):

        pix = QPixmap('../static/img/设置框架.png')  # 取图
        background = QLabel(self)
        background.setGeometry(0, 0, 400, 410)
        background.setPixmap(pix)  # 把图片放入label
        background.setScaledContents(True)  # 自适应QLabel大小

        # 切换背景
        lb1 = QLabel("设置", self)
        lb1.setGeometry(10, -2, 100, 30)
        font1 = QFont()  # 创建一个格式对象
        font1.setPixelSize(RATIO(25))  # 设置字体大小
        font1.setFamily("Microsoft YaHei")  # 设置字体
        font1.setBold(True)  # 加粗
        lb1.setFont(font1)  # 将lb1设置font1格式

        # 设置关闭按钮
        btn_close = QPushButton(self)
        btn_close.setGeometry(372, 2, 26, 26)
        btn_close.setStyleSheet("QPushButton{border-image: url(../static/img/关闭.png)}"
                                "QPushButton:hover{border-image: url(../static/img/关闭2.png)}")
        btn_close.clicked.connect(self.close)
        # 设置提示按钮
        btn_tip = QPushButton(self)
        btn_tip.setGeometry(320, 2, 26, 26)
        btn_tip.setStyleSheet("QPushButton{border-image: url(../static/img/问号.png)}"
                              "QPushButton:hover{border-image: url(../static/img/问号1.png)}")
        btn_tip.clicked.connect(self.tip)

        # 设置提示按钮
        self.btn_reset = QPushButton(self)
        self.btn_reset.setGeometry(346, 2, 26, 26)
        self.btn_reset.setStyleSheet("QPushButton{border-image: url(../static/img/格式化图标1.png)}"
                              "QPushButton:hover{border-image: url(../static/img/格式化图标2.png)}")

        # 设置确定按钮
        btn_y = QPushButton(self)
        btn_y.setText("应用")
        btn_y.setGeometry(198, 370, 202, 40)
        font1 = QFont()  # 创建一个格式对象
        font1.setPixelSize(RATIO(25))  # 设置字体大小
        font1.setFamily("Microsoft YaHei")  # 设置字体
        font1.setBold(True)  # 加粗
        btn_y.setFont(font1)
        btn_y.clicked.connect(self.apply_btn)

        # 设置取消按钮
        btn_c = QPushButton(self)
        btn_c.setText("取消")
        btn_c.setGeometry(0, 370, 200, 40)
        font2 = QFont()  # 创建一个格式对象
        font2.setPixelSize(RATIO(25))  # 设置字体大小
        font2.setFamily("Microsoft YaHei")  # 设置字体
        font2.setBold(True)  # 加粗
        btn_c.setFont(font2)
        btn_c.clicked.connect(self.close)

    def tip(self):
        msg_box = QMessageBox(QMessageBox.Information, '提示', read_setting("提示"))
        font1 = QFont()  # 创建一个格式对象
        font1.setPixelSize(RATIO(20))  # 设置字体大小
        font1.setFamily("Microsoft YaHei")  # 设置字体
        msg_box.setFont(font1)
        msg_box.exec_()

    # 设置标签
    def set_labels(self):
        # 切换背景
        lb1 = QLabel("切换背景：", self)
        lb1.setGeometry(10, 40, 150, 30)
        font1 = QFont()  # 创建一个格式对象
        font1.setPixelSize(RATIO(25))  # 设置字体大小
        font1.setFamily("Microsoft YaHei")  # 设置字体
        font1.setBold(True)  # 加粗
        lb1.setFont(font1)  # 将lb1设置font1格式

        # 设置教学周
        lb2 = QLabel("设置教学周：", self)
        lb2.setGeometry(10, 195, 200, 30)
        font2 = QFont()  # 创建一个格式对象
        font2.setPixelSize(RATIO(25))  # 设置字体大小
        font2.setFamily("Microsoft YaHei")  # 设置字体
        font2.setBold(True)  # 加粗
        lb2.setFont(font2)  # 将lb1设置font1格式

        # 设置默认天气地点
        lb3 = QLabel("设置默认天气地点：", self)
        lb3.setGeometry(10, 285, 250, 30)
        font3 = QFont()  # 创建一个格式对象
        font3.setPixelSize(RATIO(25))  # 设置字体大小
        font3.setFamily("Microsoft YaHei")  # 设置字体
        font3.setBold(True)  # 加粗
        lb3.setFont(font3)  # 将lb1设置font1格式

    # 设置按钮图片
    def set_img(self):
        # 设置背景1
        self.img_btn_1 = QPushButton(self)
        self.img_btn_1.setGeometry(10, 80, 120, 100)
        if self.background_img == "背景1":
            self.img_btn_1.setStyleSheet("QPushButton{border-image: url(../static/img/背景1_1.png)}")
        else:
            self.img_btn_1.setStyleSheet("QPushButton{border-image: url(../static/img/背景1.png)}"
                                         "QPushButton:hover{border-image: url(../static/img/背景1_3.png)}")
        self.img_btn_1.clicked.connect(self.set_img_btn_1)
        # 设置背景2
        self.img_btn_2 = QPushButton(self)
        self.img_btn_2.setGeometry(140, 80, 120, 100)
        if self.background_img == "背景2":
            self.img_btn_2.setStyleSheet("QPushButton{border-image: url(../static/img/背景2_1.png)}")
        else:
            self.img_btn_2.setStyleSheet("QPushButton{border-image: url(../static/img/背景2.png)}"
                                         "QPushButton:hover{border-image: url(../static/img/背景2_3.png)}")
        self.img_btn_2.clicked.connect(self.set_img_btn_2)
        # 设置背景4
        self.img_btn_3 = QPushButton(self)
        self.img_btn_3.setGeometry(270, 80, 120, 100)
        if self.background_img == "背景4":
            self.img_btn_3.setStyleSheet("QPushButton{border-image: url(../static/img/背景4_1.png)}")
        else:
            self.img_btn_3.setStyleSheet("QPushButton{border-image: url(../static/img/背景4.png)}"
                                         "QPushButton:hover{border-image: url(../static/img/背景4_3.png)}")
        self.img_btn_3.clicked.connect(self.set_img_btn_3)

    # 教学周输入框
    def set_teaching_edit(self):

        # 首周首周内的一天
        self.edit1 = QDateTimeEdit(QDateTime.currentDateTime(), self)
        self.edit1.setDisplayFormat("yyyy年MM月dd日")
        self.edit1.setGeometry(10, 237, 150, 30)
        self.edit1.setCalendarPopup(True)
        x = read_setting("教学周")
        d_1 = QDate(int(x.split("年")[0]), int(x.split("年")[1].split("月")[0]),
                    int(x.split("年")[1].split("月")[1].split("日")[0]))
        self.edit1.setDate(d_1)
        font1 = QFont()  # 创建一个格式对象
        font1.setPixelSize(15)  # 设置字体大小
        font1.setFamily("Microsoft YaHei")  # 设置字体
        # font1.setBold(True)  # 加粗
        self.edit1.setFont(font1)  # 将lb1设置font1格式

        # 持续时间
        self.edit2 = QLineEdit(self)
        self.edit2.setGeometry(200, 237, 100, 30)
        self.edit2.setPlaceholderText(read_setting("持续时间"))
        int_num = QIntValidator()
        int_num.setRange(0, 30)
        self.edit2.setValidator(int_num)
        font2 = QFont()  # 创建一个格式对象
        font2.setPixelSize(15)  # 设置字体大小
        font2.setFamily("Microsoft YaHei")  # 设置字体
        # font1.setBold(True)  # 加粗
        self.edit2.setFont(font2)  # 将lb1设置font1格式

    # 天气地址输入框
    def set_weather_address(self):
        # 输入地点
        self.edit3 = QLineEdit(self)
        self.edit3.setGeometry(10, 325, 100, 30)
        self.edit3.setPlaceholderText(read_setting("地址"))
        font1 = QFont()  # 创建一个格式对象
        font1.setPixelSize(15)  # 设置字体大小
        font1.setFamily("Microsoft YaHei")  # 设置字体
        # font1.setBold(True)  # 加粗
        self.edit3.setFont(font1)  # 将lb1设置font1格式

    # 图片按钮1
    def set_img_btn_1(self):
        self.img_btn_1.setStyleSheet("QPushButton{border-image: url(../static/img/背景1_1.png)}")
        self.img_btn_2.setStyleSheet("QPushButton{border-image: url(../static/img/背景2.png)}"
                                     "QPushButton:hover{border-image: url(../static/img/背景2_3.png)}")
        self.img_btn_3.setStyleSheet("QPushButton{border-image: url(../static/img/背景4.png)}"
                                     "QPushButton:hover{border-image: url(../static/img/背景4_3.png)}")
        self.background_img = "背景1"

    # 图片按钮2
    def set_img_btn_2(self):
        self.img_btn_2.setStyleSheet("QPushButton{border-image: url(../static/img/背景2_1.png)}")
        self.img_btn_1.setStyleSheet("QPushButton{border-image: url(../static/img/背景1.png)}"
                                     "QPushButton:hover{border-image: url(../static/img/背景1_3.png)}")
        self.img_btn_3.setStyleSheet("QPushButton{border-image: url(../static/img/背景4.png)}"
                                     "QPushButton:hover{border-image: url(../static/img/背景4_3.png)}")
        self.background_img = "背景2"

    # 图片按钮3
    def set_img_btn_3(self):
        self.img_btn_3.setStyleSheet("QPushButton{border-image: url(../static/img/背景4_1.png)}")
        self.img_btn_2.setStyleSheet("QPushButton{border-image: url(../static/img/背景2.png)}"
                                     "QPushButton:hover{border-image: url(../static/img/背景2_3.png)}")
        self.img_btn_1.setStyleSheet("QPushButton{border-image: url(../static/img/背景1.png)}"
                                     "QPushButton:hover{border-image: url(../static/img/背景1_3.png)}")

        self.background_img = "背景4"

    # 确认按钮
    def apply_btn(self):
        # 修改默认地址
        if len(self.edit3.text()) > 0:
            try:
                get_weather(self.edit3.text())
                update_setting("地址", self.edit3.text())
            except:
                msg_box = QMessageBox(QMessageBox.Critical, '错误', '未找到指定地点或网络未连接')
                font1 = QFont()  # 创建一个格式对象
                font1.setPixelSize(RATIO(20))  # 设置字体大小
                font1.setFamily("Microsoft YaHei")  # 设置字体
                msg_box.setFont(font1)
                msg_box.exec_()
                self.edit3.clear()
                return
        # 修改背景
        update_setting("背景", self.background_img)
        self.change_backgruond_signal.emit(self.background_img)

        # 修改教学周
        update_setting("教学周", str(int(self.edit1.text().split("年")[0])) + "年" + str(
            int(self.edit1.text().split("年")[1].split("月")[0])) + "月" + str(
            int(self.edit1.text().split("年")[1].split("月")[1].split("日")[0])) + "日")
        if len(self.edit2.text()) > 0:
            update_setting("持续时间", self.edit2.text())
        # 发送信号

        self.change_teaching_week_address_signal.emit("")

        self.close()



    """去除工具栏后重写点击移动函数"""

    def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton:
            self.m_flag = True
            self.m_Position = event.globalPos() - self.pos()  # 获取鼠标相对窗口的位置
            event.accept()

    def mouseMoveEvent(self, QMouseEvent):
        try:
            if Qt.LeftButton and self.m_flag:
                self.move(QMouseEvent.globalPos() - self.m_Position)  # 更改窗口位置
                QMouseEvent.accept()
        except Exception:
            pass

    def mouseReleaseEvent(self, QMouseEvent):
        self.m_flag = False
        self.setCursor(QCursor(Qt.ArrowCursor))


# 日程对话窗
class Schedulewindow(QWidget):
    open_add_event_window_signal = pyqtSignal(str)

    def __init__(self, date="2022,10,23"):
        super().__init__()
        self.date = date
        self.date_list = []
        self.init_ui()

    # 初始化ui函数
    def init_ui(self):
        self.resize(140, 180)  # 设置窗口大小
        self.setFixedSize(140, 180)  # 固定大小
        self.setWindowFlags(Qt.FramelessWindowHint)  # 去边框化
        self.setAttribute(Qt.WA_TranslucentBackground)  # 设置窗口背景透明
        self.setWindowIcon(QIcon("../static/img/logo1.png"))

        ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID("myappid")

        # 设置背景
        self.set_background()

        self.having_event = False  # 当天是否有事件

        with open("../event/event.json", "r") as f:
            events = json.load(f)
        for id, event in events.items():
            # 开始时间
            start_time = datetime.datetime(int(event["start_time"].split(",")[0]),
                                           int(event["start_time"].split(",")[1]),
                                           int(event["start_time"].split(",")[2]), 0, 0)
            # 结束时间
            end_time = datetime.datetime(int(event["end_time"].split(",")[0]), int(event["end_time"].split(",")[1]),
                                         int(event["end_time"].split(",")[2]), 23, 0)
            # 当前时间
            now_time = datetime.datetime(int(self.date.split(",")[0]), int(self.date.split(",")[1]),
                                         int(self.date.split(",")[2]), 12, 0)
            # 判断当前时间是否在范围时间内
            if start_time < now_time < end_time:
                self.date_list.append(id)
                self.having_event = True

        if self.having_event:
            self.set_event_window()

        # 设置添加日程按钮
        if self.having_event == False:
            self.set_add_schedule()

    def set_event_window(self):
        scroll = QScrollArea(self)
        scroll.setGeometry(10, 5, 120, 100)
        scroll.setFixedSize(120, 100)
        self.e_window = event_list_window(self.date_list)
        self.e_window.open_event_singal.connect(self.open_event)
        self.e_window.add_event_singal.connect(self.open_add_event_window)
        scroll.setWidget(self.e_window)
        scroll.setFrameShape(QFrame.NoFrame)
        scroll.setStyleSheet("QScrollArea {background-color:transparent;}")
        scroll.viewport().setStyleSheet("background-color:transparent;")
        scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        scroll.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)

    # 设置对话窗背景
    def set_background(self):
        # 设置背景函数
        pix = QPixmap('../static/img/对话框1.png')  # 取图
        self.background = QLabel(self)
        self.background.setGeometry(0, 0, 140, 180)
        self.background.setPixmap(pix)  # 把图片放入label

    # 设置添加日程按钮
    def set_add_schedule(self):
        # 设置背景1
        self.img_add_schedule_btn = QPushButton(self)
        self.img_add_schedule_btn.setGeometry(25, 10, 90, 90)
        self.img_add_schedule_btn.setStyleSheet("QPushButton{border-image: url(../static/img/添加日程1.png)}"
                                                "QPushButton:hover{border-image: url(../static/img/添加日程2.png)}")
        self.img_add_schedule_btn.clicked.connect(self.open_add_event_window)

    # 发送添加事件信号
    def open_add_event_window(self):
        self.open_add_event_window_signal.emit(self.date)
        self.close()

    # 发送打开信号
    def open_event(self, s):
        self.open_add_event_window_signal.emit(s)
        self.close()

    """去除工具栏后重写点击移动函数"""

    def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton:
            self.m_flag = True
            self.m_Position = event.globalPos() - self.pos()  # 获取鼠标相对窗口的位置
            event.accept()

    def mouseMoveEvent(self, QMouseEvent):
        try:
            if Qt.LeftButton and self.m_flag:
                self.move(QMouseEvent.globalPos() - self.m_Position)  # 更改窗口位置
                QMouseEvent.accept()
        except Exception:
            pass

    def mouseReleaseEvent(self, QMouseEvent):
        self.m_flag = False
        self.setCursor(QCursor(Qt.ArrowCursor))


# 日程对话窗口中的日程罗列
class event_list_window(QWidget):
    open_event_singal = pyqtSignal(str)
    add_event_singal = pyqtSignal(str)

    def __init__(self, event_list):
        super().__init__()
        self.event_list = event_list
        self.btn_list = []
        self.init_ui()

    # 初始化ui函数
    def init_ui(self):
        h = (len(self.event_list) + 1) * 40 + 10
        self.resize(120, h)  # 设置窗口大小
        self.setFixedSize(120, h)  # 固定大小
        self.setWindowFlags(Qt.FramelessWindowHint)  # 去边框化
        self.setAttribute(Qt.WA_TranslucentBackground)  # 设置窗口背景透明
        self.set_background(h)
        self.set_btn()

    def set_background(self, h):
        # 设置背景函数
        pix = QPixmap('../static/img/对话框1.png')  # 取图
        self.background = QLabel(self)
        self.background.setGeometry(-30, -30, 2000, h + 1000)
        self.background.setPixmap(pix)  # 把图片放入label

    def set_btn(self):
        with open("../event/event.json", "r") as f:
            events = json.load(f)
        count = 0
        for i in self.event_list:
            if len(events[i]["title"]) > 5:
                name = events[i]["title"][0:5] + ".."
            else:
                name = events[i]["title"]
            btn = QPushButton(events[i]["event_type"] + " " + name, self)
            btn.setGeometry(10, 10 + count * 40, 100, 30)
            self.btn_list.append(btn)
            self.btn_list[count].text()
            self.btn_list[count].clicked.connect(lambda: self.open_event(self.sender().y()))
            count = count + 1

        self.add_btn = QPushButton("+ 添加日程", self)
        self.add_btn.setGeometry(10, 10 + count * 40, 100, 30)
        self.add_btn.clicked.connect(self.add_event)

    def open_event(self, s):
        self.open_event_singal.emit(self.event_list[int((int(s) - 10) / 40)])

    def add_event(self):
        self.add_event_singal.emit("")

    """去除工具栏后重写点击移动函数"""

    def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton:
            self.m_flag = True
            self.m_Position = event.globalPos() - self.pos()  # 获取鼠标相对窗口的位置
            event.accept()

    # def mouseMoveEvent(self, QMouseEvent):
    #     try:
    #         if Qt.LeftButton and self.m_flag:
    #             self.move(QMouseEvent.globalPos() - self.m_Position)  # 更改窗口位置
    #             QMouseEvent.accept()
    #     except Exception:
    #         pass

    def mouseReleaseEvent(self, QMouseEvent):
        self.m_flag = False
        self.setCursor(QCursor(Qt.ArrowCursor))


# 小重复设置对话框
class re_window_1(QWidget):
    time_signal = pyqtSignal(str)  # 时间修改信号
    close_signal = pyqtSignal(str)  # 关闭信号

    def __init__(self):
        super().__init__()
        self.init_ui()

    # 初始化ui函数
    def init_ui(self):
        self.resize(200, 100)  # 设置窗口大小
        self.setFixedSize(200, 100)  # 固定大小
        self.setWindowFlags(Qt.FramelessWindowHint)  # 去边框化
        self.setAttribute(Qt.WA_TranslucentBackground)  # 设置窗口背景透明
        self.setWindowIcon(QIcon("../static/img/logo1.png"))

        ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID("myappid")
        # 设置背景
        self.set_background_1()
        self.set_content_1()

    # 设置对话窗背景
    def set_background_1(self):
        # 设置背景函数
        pix = QPixmap('../static/img/小重复对话框.png')  # 取图
        self.background = QLabel(self)
        self.background.setGeometry(0, 0, 200, 100)
        self.background.setPixmap(pix)  # 把图片放入label

    # 设置小对话框中的内容
    def set_content_1(self):
        # 提示标签
        self.class_label = QLabel("提醒时间：", self)
        self.class_label.setGeometry(5, 28, 120, 30)
        font1 = QFont()  # 创建一个格式对象
        font1.setPixelSize(RATIO(25))  # 设置字体大小
        font1.setFamily("Microsoft YaHei")  # 设置字体
        font1.setBold(True)  # 加粗
        self.class_label.setFont(font1)  # 将lb1设置font1格式

        # 时间输入框
        self.time_edit = QTimeEdit(self)
        self.time_edit.setDisplayFormat("HH:mm")
        self.time_edit.setGeometry(120, 30, 70, 30)
        time = QTime(12, 00)
        self.time_edit.setTime(time)
        font2 = QFont()  # 创建一个格式对象
        font2.setPixelSize(14)  # 设置字体大小
        font2.setFamily("Microsoft YaHei")  # 设置字体
        # font1.setBold(True)  # 加粗
        self.time_edit.setFont(font2)  # 将lb1设置font1格3
        self.time_edit.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)  # 靠右上下居中

        # 设置确定按钮
        self.save_btn = QPushButton("确定", self)
        self.save_btn.setGeometry(75, 65, 50, 30)
        font3 = QFont()  # 创建一个格式对象
        font3.setPixelSize(15)  # 设置字体大小
        font3.setFamily("Microsoft YaHei")  # 设置字体
        self.save_btn.setFont(font3)
        self.save_btn.clicked.connect(self.change_time)

    # 发送时间修改信号
    def change_time(self):
        self.time_signal.emit(self.time_edit.text())
        self.close_signal.emit("")
        self.close()

    """去除工具栏后重写点击移动函数"""

    def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton:
            self.m_flag = True
            self.m_Position = event.globalPos() - self.pos()  # 获取鼠标相对窗口的位置
            event.accept()

    def mouseMoveEvent(self, QMouseEvent):
        try:
            if Qt.LeftButton and self.m_flag:
                self.move(QMouseEvent.globalPos() - self.m_Position)  # 更改窗口位置
                QMouseEvent.accept()
        except Exception:
            pass

    def mouseReleaseEvent(self, QMouseEvent):
        self.m_flag = False
        self.setCursor(QCursor(Qt.ArrowCursor))


# 大重复设置对话框
class re_window_2(QWidget):
    time_signal = pyqtSignal(str)  # 修改重复提醒时间信号
    week_signal = pyqtSignal(str)  # 修改重复周信号
    close_signal = pyqtSignal(str)  # 关闭信号

    def __init__(self):
        super().__init__()
        self.init_ui()

    # 初始化ui函数
    def init_ui(self):
        self.resize(300, 200)  # 设置窗口大小
        self.setFixedSize(300, 200)  # 固定大小
        self.setWindowFlags(Qt.FramelessWindowHint)  # 去边框化
        self.setAttribute(Qt.WA_TranslucentBackground)  # 设置窗口背景透明
        self.setWindowIcon(QIcon("../static/img/logo1.png"))

        ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID("myappid")
        # 设置背景
        self.set_background_2()
        self.set_content_2()

    # 设置对话窗背景
    def set_background_2(self):
        # 设置背景函数
        pix = QPixmap('../static/img/大重复对话框.png')  # 取图
        self.background = QLabel(self)
        self.background.setGeometry(0, 0, 300, 200)
        self.background.setPixmap(pix)  # 把图片放入label

    # 设置大对话框中的内容
    def set_content_2(self):
        # 提示标签
        self.class_label = QLabel("提醒时间：", self)
        self.class_label.setGeometry(55, 40, 120, 30)
        font1 = QFont()  # 创建一个格式对象
        font1.setPixelSize(RATIO(25))  # 设置字体大小
        font1.setFamily("Microsoft YaHei")  # 设置字体
        font1.setBold(True)  # 加粗
        self.class_label.setFont(font1)  # 将lb1设置font1格式

        # 时间输入框
        self.time_edit = QTimeEdit(self)
        self.time_edit.setDisplayFormat("HH:mm")
        self.time_edit.setGeometry(175, 42, 70, 30)
        time = QTime(12, 00)
        self.time_edit.setTime(time)
        font2 = QFont()  # 创建一个格式对象
        font2.setPixelSize(14)  # 设置字体大小
        font2.setFamily("Microsoft YaHei")  # 设置字体
        # font1.setBold(True)  # 加粗
        self.time_edit.setFont(font2)  # 将lb1设置font1格3
        self.time_edit.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)  # 靠右上下居中

        # 设置周一按钮
        self.btn_1 = QCheckBox("周一", self)
        self.btn_1.setGeometry(5, 80, 70, 30)
        font3 = QFont()  # 创建一个格式对象
        font3.setPixelSize(15)  # 设置字体大小
        font3.setFamily("Microsoft YaHei")  # 设置字体
        self.btn_1.setFont(font3)
        # 设置周二按钮
        self.btn_2 = QCheckBox("周二", self)
        self.btn_2.setGeometry(80, 80, 70, 30)
        font3 = QFont()  # 创建一个格式对象
        font3.setPixelSize(15)  # 设置字体大小
        font3.setFamily("Microsoft YaHei")  # 设置字体
        self.btn_2.setFont(font3)
        # 设置周三按钮
        self.btn_3 = QCheckBox("周三", self)
        self.btn_3.setGeometry(155, 80, 70, 30)
        font3 = QFont()  # 创建一个格式对象
        font3.setPixelSize(15)  # 设置字体大小
        font3.setFamily("Microsoft YaHei")  # 设置字体
        self.btn_3.setFont(font3)
        # 设置周四按钮
        self.btn_4 = QCheckBox("周四", self)
        self.btn_4.setGeometry(230, 80, 70, 30)
        font3 = QFont()  # 创建一个格式对象
        font3.setPixelSize(15)  # 设置字体大小
        font3.setFamily("Microsoft YaHei")  # 设置字体
        self.btn_4.setFont(font3)
        # 设置周五按钮
        self.btn_5 = QCheckBox("周五", self)
        self.btn_5.setGeometry(5, 120, 70, 30)
        font3 = QFont()  # 创建一个格式对象
        font3.setPixelSize(15)  # 设置字体大小
        font3.setFamily("Microsoft YaHei")  # 设置字体
        self.btn_5.setFont(font3)
        # 设置周六按钮
        self.btn_6 = QCheckBox("周六", self)
        self.btn_6.setGeometry(80, 120, 70, 30)

        font3 = QFont()  # 创建一个格式对象
        font3.setPixelSize(15)  # 设置字体大小
        font3.setFamily("Microsoft YaHei")  # 设置字体
        self.btn_6.setFont(font3)
        # 设置周日按钮
        self.btn_7 = QCheckBox("周日", self)
        self.btn_7.setGeometry(155, 120, 70, 30)
        font3 = QFont()  # 创建一个格式对象
        font3.setPixelSize(15)  # 设置字体大小
        font3.setFamily("Microsoft YaHei")  # 设置字体
        self.btn_7.setFont(font3)

        # 设置确定按钮
        self.save_btn = QPushButton("确定", self)
        self.save_btn.setGeometry(125, 160, 50, 30)
        font3 = QFont()  # 创建一个格式对象
        font3.setPixelSize(15)  # 设置字体大小
        font3.setFamily("Microsoft YaHei")  # 设置字体
        self.save_btn.setFont(font3)
        self.save_btn.clicked.connect(self.change_time_week)

    # 发送时间修改信号
    def change_time_week(self):
        self.time_signal.emit(self.time_edit.text())
        self.week_signal.emit(self.get_week())
        self.close_signal.emit("")
        self.close()

    # 获取多选框值
    def get_week(self):

        re_week = ""
        if self.btn_1.isChecked() == True:
            re_week = "1" + re_week
        if self.btn_2.isChecked() == True:
            re_week = "2" + re_week
        if self.btn_3.isChecked() == True:
            re_week = "3" + re_week
        if self.btn_4.isChecked() == True:
            re_week = "4" + re_week
        if self.btn_5.isChecked() == True:
            re_week = "5" + re_week
        if self.btn_6.isChecked() == True:
            re_week = "6" + re_week
        if self.btn_7.isChecked() == True:
            re_week = "7" + re_week

        return re_week

    # 设置多选框
    def set_checkbox(self, s):
        if "1" in s:
            self.btn_1.setChecked(True)
        else:
            self.btn_1.setChecked(False)
        if "2" in s:
            self.btn_2.setChecked(True)
        else:
            self.btn_2.setChecked(False)
        if "3" in s:
            self.btn_3.setChecked(True)
        else:
            self.btn_3.setChecked(False)
        if "4" in s:
            self.btn_4.setChecked(True)
        else:
            self.btn_4.setChecked(False)
        if "5" in s:
            self.btn_5.setChecked(True)
        else:
            self.btn_5.setChecked(False)
        if "6" in s:
            self.btn_6.setChecked(True)
        else:
            self.btn_6.setChecked(False)
        if "7" in s:
            self.btn_7.setChecked(True)
        else:
            self.btn_7.setChecked(False)

    """去除工具栏后重写点击移动函数"""

    def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton:
            self.m_flag = True
            self.m_Position = event.globalPos() - self.pos()  # 获取鼠标相对窗口的位置
            event.accept()

    def mouseMoveEvent(self, QMouseEvent):
        try:
            if Qt.LeftButton and self.m_flag:
                self.move(QMouseEvent.globalPos() - self.m_Position)  # 更改窗口位置
                QMouseEvent.accept()
        except Exception:
            pass

    def mouseReleaseEvent(self, QMouseEvent):
        self.m_flag = False
        self.setCursor(QCursor(Qt.ArrowCursor))


# 日程信息窗口
class Schedule_msg_window(QWidget):
    # 创建自定义信号
    open_re_window_signal = pyqtSignal(str)  # 打开重复设置窗口信号
    close_window_signal = pyqtSignal(str)  # 点击主窗口关闭其他子窗口
    check_img_signal = pyqtSignal(str)
    play_video_signal = pyqtSignal(str)
    update_signal = pyqtSignal(str)

    def __init__(self, id="s_0"):
        super().__init__()

        if id[0] == "s":
            self.is_new_event = False
        else:
            self.is_new_event = True

        self.init_ui()

        self.id = id  # 事件id

        self.title = self.title_edit.text()

        # 事件开始时间
        self.start_time = str(self.dateEdit1.date().getDate()[0]) + "," + str(
            self.dateEdit1.date().getDate()[1]) + "," + str(self.dateEdit1.date().getDate()[2]) + "," + \
                          str(self.dateEdit1.dateTime().time().hour()) + "," + str(
            self.dateEdit1.dateTime().time().minute())
        # 事件结束时间
        self.end_time = str(self.dateEdit2.date().getDate()[0]) + "," + str(
            self.dateEdit2.date().getDate()[1]) + "," + str(self.dateEdit2.date().getDate()[2]) + "," + \
                        str(self.dateEdit2.dateTime().time().hour()) + "," + str(
            self.dateEdit2.dateTime().time().minute())

        self.event_type = self.type_label.text()  # 事件类型

        self.content = self.content_edit.toPlainText()  # 事件内容描述

        self.re_week = ""  # 重复哪些周

        self.re_time = "12:00"  # 重复提醒时间

        # 重复信息
        self.remind_msg = self.time_combo.currentText() + "," + self.re_combo.currentText() + \
                          "," + self.re_time + "," + self.re_week

        # 照片地址字典
        self.images_address_dict = {}

        # 视频地址字典
        self.video_address_dict = {}

        # 删除照片缓冲区
        self.delect_img_list = []

        self.images = ""  # 照片

        self.videos = ""  # 视频

        # 处理窗口初始化
        self.thread.w_re_2.re_week = self.re_week

        self.init_event()  # 初始化事件

    """初始化函数"""

    # 初始化ui函数
    def init_ui(self):
        self.resize(600, 450)  # 设置窗口大小
        self.setFixedSize(600, 450)  # 固定大小
        self.setObjectName("MainWindow")
        self.setStyleSheet("#MainWindow{background-color:white}")
        self.setWindowFlags(Qt.FramelessWindowHint)  # 去边框化
        self.setWindowIcon(QIcon("../static/img/logo1.png"))

        ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID("myappid")
        self.set_menu_bar_background()  # 设置菜单栏背景
        self.set_menu_bar_items()  # 设置菜单栏
        self.set_main_label()  # 设置正文标签
        self.image_bar()  # 图片区域
        self.video_bar()  # 视频区域

        self.thread = Schedule_Thread()
        # 线程信号连接
        self.thread.w_re_1.time_signal.connect(self.change_re_time)
        self.thread.w_re_2.time_signal.connect(self.change_re_time)
        self.thread.w_re_2.week_signal.connect(self.change_re_week)
        self.thread.get_re_time_signal.connect(self.change_thread_re_time)
        self.thread.get_re_week_signal.connect(self.change_thread_re_week)
        # 本地信号连接
        self.open_re_window_signal.connect(self.thread.open_re_window)
        self.close_window_signal.connect(self.thread.close_window)
        self.check_img_signal.connect(self.thread.check_img)
        self.play_video_signal.connect(self.thread.play_video)

        self.thread.start()

    # 初始化事件函数
    def init_event(self):
        having = False
        with open("../event/event.json", "r") as f:
            data = json.load(f)
        for id, event in data.items():
            if self.id == id:
                self.title = event["title"]
                self.title_edit.setText(self.title)
                self.start_time = event["start_time"]
                self.end_time = event["end_time"]
                self.init_time()
                self.event_type = event["event_type"]
                if self.event_type == "📖":
                    self.class_combo.setCurrentIndex(0)
                elif self.event_type == "🏀":
                    self.class_combo.setCurrentIndex(1)
                elif self.event_type == "🎮":
                    self.class_combo.setCurrentIndex(2)
                else:
                    self.class_combo.setCurrentIndex(3)
                self.type_label.setText(self.event_type)
                self.content = event["content"]
                self.content_edit.setText(self.content)
                self.remind_msg = event["remind_msg"]
                self.re_time = self.remind_msg.split(",")[2]
                self.init_re()
                self.init_img()
                self.init_video()
                self.re_week = self.remind_msg.split(",")[3]
                having = True
                self.is_new_event = False
        if having == False:
            # 设置开始时间
            d_1 = QDate(int(self.id.split(",")[0]), int(self.id.split(",")[1]), int(self.id.split(",")[2]))
            if int(self.id.split(",")[0]) == datetime.datetime.now().year and int(
                    self.id.split(",")[1]) == datetime.datetime.now().month and int(
                self.id.split(",")[2]) == datetime.datetime.now().day:
                time_1 = QTime(datetime.datetime.now().hour, datetime.datetime.now().minute)
            else:
                time_1 = QTime(12, 0)
            t_1 = QDateTime(d_1, time_1)
            self.dateEdit1.setDateTime(t_1)
            # 设置结束时间
            d = QDate(int(self.id.split(",")[0]), int(self.id.split(",")[1]), int(self.id.split(",")[2]))
            time = QTime(23, 59)
            t = QDateTime(d, time)
            self.dateEdit2.setDateTime(t)

    # 初始化起始时间
    def init_time(self):
        # 设置开始时间
        d_1 = QDate(int(self.start_time.split(",")[0]), int(self.start_time.split(",")[1]),
                    int(self.start_time.split(",")[2]))
        time_1 = QTime(int(self.start_time.split(",")[3]), int(self.start_time.split(",")[4]))
        t_1 = QDateTime(d_1, time_1)
        self.dateEdit1.setDateTime(t_1)
        # 设置结束时间
        d = QDate(int(self.end_time.split(",")[0]), int(self.end_time.split(",")[1]), int(self.end_time.split(",")[2]))
        time = QTime(int(self.end_time.split(",")[3]), int(self.end_time.split(",")[4]))
        t = QDateTime(d, time)
        self.dateEdit2.setDateTime(t)

    # 初始化菜单栏重复选项
    def init_re(self):
        r_s = self.remind_msg.split(",")[0]
        if r_s == "无":
            self.time_combo.setCurrentIndex(0)
        elif r_s == "无提前":
            self.time_combo.setCurrentIndex(1)
        elif r_s == "0分钟":
            self.time_combo.setCurrentIndex(2)
        elif r_s == "5分钟":
            self.time_combo.setCurrentIndex(3)
        elif r_s == "15分钟":
            self.time_combo.setCurrentIndex(4)
        elif r_s == "30分钟":
            self.time_combo.setCurrentIndex(5)
        elif r_s == "1小时":
            self.time_combo.setCurrentIndex(6)
        elif r_s == "12小时":
            self.time_combo.setCurrentIndex(7)
        elif r_s == "1天":
            self.time_combo.setCurrentIndex(8)
        else:
            self.time_combo.setCurrentIndex(9)
        self.set_re_1(r_s)

        re_s = self.remind_msg.split(",")[1]
        if re_s == "无":
            self.re_combo.setCurrentIndex(0)
        elif re_s == "每天":
            self.re_combo.setCurrentIndex(1)
        else:
            self.re_combo.setCurrentIndex(2)
        if r_s != "无":
            self.set_re_2(re_s)

        # 设置菜单栏背景

    # 初始化图片
    def init_img(self):
        if os.path.exists('../event/images/%s' % self.id):
            f = True  # 展现第一张图片
            name_list = os.listdir('../event/images/%s' % self.id)
            for name in name_list:
                self.images_address_dict.update({name: '../event/images/%s/%s' % (self.id, name)})
                self.img_combo.addItem(name)
                if f:
                    self.select_img(name)
                    f = False
                    self.check_btn.show()

    # 初始化视频
    def init_video(self):
        if os.path.exists('../event/videos/%s' % self.id):
            f = True  # 展现第一张图片
            name_list = os.listdir('../event/videos/%s' % self.id)
            for name in name_list:
                self.video_address_dict.update({name: '../event/videos/%s/%s' % (self.id, name)})
                self.video_combo.addItem(name)
                if f:
                    self.select_video(name)
                    f = False
                    self.play_btn.show()

    # 设置背景
    def set_menu_bar_background(self):

        pix = QPixmap('../static/img/淡灰色菜单栏.png')  # 取图
        self.menu_bar_background = QLabel(self)
        self.menu_bar_background.setGeometry(0, 0, 600, 30)
        self.menu_bar_background.setPixmap(pix)  # 把图片放入label
        self.menu_bar_background.setScaledContents(True)  # 自适应QLabel大小

        # 设置外边框
        pix = QPixmap('../static/img/外边框.png')  # 取图
        self.menu_bar_background = QLabel(self)
        self.menu_bar_background.setGeometry(0, 0, 600, 450)
        self.menu_bar_background.setPixmap(pix)  # 把图片放入label
        self.menu_bar_background.setScaledContents(True)  # 自适应QLabel大小

    # 设置菜单栏
    def set_menu_bar_items(self):
        # 设置保存按钮
        self.save_btn = QPushButton(self)
        self.save_btn.setGeometry(1, 1, 70, 28)
        self.save_btn.setStyleSheet("QPushButton{border-image: url(../static/img/保存图标1.png)}"
                                    "QPushButton:hover{border-image: url(../static/img/保存图标2.png)}")
        self.save_btn.clicked.connect(self.save)

        # 设置删除按钮
        self.delete_btn = QPushButton(self)
        self.delete_btn.setGeometry(71, 1, 70, 28)
        self.delete_btn.setStyleSheet("QPushButton{border-image: url(../static/img/删除图标1.png)}"
                                      "QPushButton:hover{border-image: url(../static/img/删除图标2.png)}")
        self.delete_btn.clicked.connect(self.delete)

        # 设置间隔竖
        pix = QPixmap('../static/img/竖.png')  # 取图
        self.vertical_img = QLabel(self)
        self.vertical_img.setGeometry(140, 5, 8, 20)
        self.vertical_img.setPixmap(pix)  # 把图片放入label
        self.vertical_img.setScaledContents(True)  # 自适应QLabel大小

        # 类型文本标签
        self.class_label = QLabel("类型：", self)
        self.class_label.setGeometry(155, 0, 50, 30)
        font1 = QFont()  # 创建一个格式对象
        font1.setPixelSize(RATIO(15))  # 设置字体大小
        font1.setFamily("Microsoft YaHei")  # 设置字体
        font1.setBold(True)  # 加粗
        self.class_label.setFont(font1)  # 将lb1设置font1格式
        self.class_label.setStyleSheet('color: grey')

        # 类型多选框
        self.class_combo = QComboBox(self)
        self.class_combo.setGeometry(195, 3, 50, 24)

        font = QFont()  # 创建一个格式对象
        font.setPixelSize(RATIO(15))  # 设置字体大小
        font.setFamily("Microsoft YaHei")  # 设置字体
        self.class_combo.setFont(font)
        self.class_combo.addItem("📖")
        self.class_combo.addItem("🏀")
        self.class_combo.addItem("🎮")
        self.class_combo.addItem("☕")
        self.class_combo.activated[str].connect(self.type_action)

        # 类型文本标签
        self.remind_label = QLabel("提醒：", self)
        self.remind_label.setGeometry(255, 0, 50, 30)
        font2 = QFont()  # 创建一个格式对象
        font2.setPixelSize(RATIO(15))  # 设置字体大小
        font2.setFamily("Microsoft YaHei")  # 设置字体
        font2.setBold(True)  # 加粗
        self.remind_label.setFont(font2)  # 将lb1设置font1格式
        self.remind_label.setStyleSheet('color: grey')

        # 提醒多选框
        self.time_combo = QComboBox(self)
        self.time_combo.setGeometry(295, 3, 65, 24)
        font6 = QFont()  # 创建一个格式对象
        font6.setPixelSize(RATIO(12))  # 设置字体大小
        font6.setFamily("Microsoft YaHei")  # 设置字体
        self.time_combo.setFont(font6)
        self.time_combo.addItem("无")
        self.time_combo.addItem("无提前")
        self.time_combo.addItem("0分钟")
        self.time_combo.addItem("5分钟")
        self.time_combo.addItem("15分钟")
        self.time_combo.addItem("30分钟")
        self.time_combo.addItem("1小时")
        self.time_combo.addItem("12小时")
        self.time_combo.addItem("1天")
        self.time_combo.addItem("1周")
        self.time_combo.activated[str].connect(self.set_re_1)
        self.time_combo.activated[str].connect(self.set_re_msg)

        # 重复文本标签
        self.re_label = QLabel("重复：", self)
        self.re_label.setGeometry(370, 0, 50, 30)
        font3 = QFont()  # 创建一个格式对象
        font3.setPixelSize(RATIO(15))  # 设置字体大小
        font3.setFamily("Microsoft YaHei")  # 设置字体
        font3.setBold(True)  # 加粗
        self.re_label.setFont(font3)  # 将lb1设置font1格式
        self.re_label.setStyleSheet('color: grey')

        # 类型多选框
        self.re_combo = QComboBox(self)
        self.re_combo.setGeometry(410, 3, 60, 24)

        self.re_combo.setFont(font6)
        self.re_combo.addItem("无")
        self.re_combo.addItem("每天")
        self.re_combo.addItem("每周")
        self.re_combo.activated[str].connect(self.set_re_2)
        self.re_combo.activated[str].connect(self.set_re_msg)

        # 设置设置按钮
        self.btn_set = QPushButton(self)
        self.btn_set.setGeometry(470, 3, 24, 24)
        self.btn_set.setStyleSheet("QPushButton{border-image: url(../static/img/重复设置图标1.png)}"
                                   "QPushButton:hover{border-image: url(../static/img/重复设置图标2.png)}")
        self.btn_set.clicked.connect(self.open_re_window)

        self.set_re_1(self.time_combo.currentText())

        # 设置关闭按钮
        self.close_btn = QPushButton(self)
        self.close_btn.setGeometry(570, 0, 30, 30)
        self.close_btn.setStyleSheet("QPushButton{border-image: url(../static/img/关闭.png)}"
                                     "QPushButton:hover{border-image: url(../static/img/关闭2.png)}")
        self.close_btn.clicked.connect(self.close)

    # 设置正文
    def set_main_label(self):

        # 详细信息标签文本
        lb1 = QLabel("详细信息：", self)
        lb1.setGeometry(10, 35, 150, 35)
        font1 = QFont()  # 创建一个格式对象
        font1.setPixelSize(RATIO(30))  # 设置字体大小
        font1.setFamily("Microsoft YaHei")  # 设置字体
        font1.setBold(True)  # 加粗
        lb1.setFont(font1)  # 将lb1设置font1格式

        # 事件标题输入框
        self.title_edit = QLineEdit(self)
        self.title_edit.setGeometry(60, 78, 200, 50)
        self.title_edit.setPlaceholderText("事件名称")
        font2 = QFont()  # 创建一个格式对象
        font2.setPixelSize(30)  # 设置字体大小
        font2.setFamily("Microsoft YaHei")  # 设置字体
        # font1.setBold(True)  # 加粗
        self.title_edit.setFont(font2)  # 将lb1设置font1格3
        self.title_edit.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)  # 靠右上下居中
        self.title_edit.textChanged.connect(self.title_edit_change)

        # 设置类型
        self.type_label = QLabel(self)
        self.type_action(self.class_combo.currentText())
        self.type_label.setGeometry(5, 76, 50, 50)
        font3 = QFont()  # 创建一个格式对象
        font3.setPixelSize(RATIO(35))  # 设置字体大小
        font3.setFamily("Microsoft YaHei")  # 设置字体
        font3.setBold(True)  # 加粗
        self.type_label.setFont(font3)  # 将lb1设置font1格式

        # 开始文本标签
        lb3 = QLabel("开始时间：", self)
        lb3.setGeometry(10, 140, 120, 30)
        font4 = QFont()  # 创建一个格式对象
        font4.setPixelSize(RATIO(25))  # 设置字体大小
        font4.setFamily("Microsoft YaHei")  # 设置字体
        font4.setBold(True)  # 加粗
        lb3.setFont(font4)  # 将lb1设置font1格式

        # 日期选择框
        self.dateEdit1 = QDateTimeEdit(QDateTime.currentDateTime(), self)
        self.dateEdit1.setDisplayFormat("yyyy年MM月dd日 HH:mm")
        self.dateEdit1.setCalendarPopup(True)
        self.dateEdit1.setGeometry(10, 175, 250, 30)

        font5 = QFont()  # 创建一个格式对象
        font5.setPixelSize(RATIO(20))  # 设置字体大小
        font5.setFamily("Microsoft YaHei")  # 设置字体
        self.dateEdit1.setFont(font5)  # 将lb1设置font1格式
        self.dateEdit1.dateTimeChanged.connect(self.start_time_change)

        # 结束文本标签
        lb4 = QLabel("结束时间：", self)
        lb4.setGeometry(10, 220, 120, 30)
        font7 = QFont()  # 创建一个格式对象
        font7.setPixelSize(RATIO(25))  # 设置字体大小
        font7.setFamily("Microsoft YaHei")  # 设置字体
        font7.setBold(True)  # 加粗
        lb4.setFont(font7)  # 将lb1设置font1格式

        # 日期选择框
        self.dateEdit2 = QDateTimeEdit(QDateTime.currentDateTime(), self)
        self.dateEdit2.setDisplayFormat("yyyy年MM月dd日 HH:mm")
        self.dateEdit2.setGeometry(10, 255, 250, 30)
        self.dateEdit2.setCalendarPopup(True)

        font8 = QFont()  # 创建一个格式对象
        font8.setPixelSize(RATIO(20))  # 设置字体大小
        font8.setFamily("Microsoft YaHei")  # 设置字体
        self.dateEdit2.setFont(font8)  # 将lb1设置font1格式
        self.dateEdit2.dateTimeChanged.connect(self.end_time_change)

        # 事件描述文本
        lb5 = QLabel("事件描述：", self)
        lb5.setGeometry(10, 300, 120, 30)
        font10 = QFont()  # 创建一个格式对象
        font10.setPixelSize(RATIO(25))  # 设置字体大小
        font10.setFamily("Microsoft YaHei")  # 设置字体
        font10.setBold(True)  # 加粗
        lb5.setFont(font10)  # 将lb1设置font1格式

        # 事件标题输入框
        self.content_edit = QTextEdit(self)
        self.content_edit.setGeometry(10, 340, 250, 90)
        self.content_edit.setPlaceholderText("请输入本事件的描述...")
        font2 = QFont()  # 创建一个格式对象
        font2.setPixelSize(20)  # 设置字体大小
        font2.setFamily("Microsoft YaHei")  # 设置字体
        # font1.setBold(True)  # 加粗
        self.content_edit.setFont(font2)  # 将lb1设置font1格3
        self.content_edit.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)  # 靠右上下居中
        self.content_edit.textChanged.connect(self.content_change)

        # 照片文本
        lb6 = QLabel("照片：", self)
        lb6.setGeometry(300, 75, 120, 35)
        font12 = QFont()  # 创建一个格式对象
        font12.setPixelSize(RATIO(30))  # 设置字体大小
        font12.setFamily("Microsoft YaHei")  # 设置字体
        font12.setBold(True)  # 加粗
        lb6.setFont(font12)

        # 视频文本
        lb7 = QLabel("视频：", self)
        lb7.setGeometry(300, 240, 120, 35)
        font13 = QFont()  # 创建一个格式对象
        font13.setPixelSize(RATIO(30))  # 设置字体大小
        font13.setFamily("Microsoft YaHei")  # 设置字体
        font13.setBold(True)  # 加粗
        lb7.setFont(font13)

        # # 设置照片添加按钮
        # self.add_btn_2 = QPushButton(self)
        # self.add_btn_2.setGeometry(300, 285, 50, 50)
        # self.add_btn_2.setStyleSheet("QPushButton{border-image: url(../static/img/添加按钮1.png)}"
        #                              "QPushButton:hover{border-image: url(../static/img/添加按钮2.png)}")

    # 设置图片处理
    def image_bar(self):

        # 图片下拉框
        self.img_combo = QComboBox(self)
        self.img_combo.setGeometry(300, 120, 115, 35)
        font1 = QFont()  # 创建一个格式对象
        font1.setPixelSize(RATIO(15))  # 设置字体大小
        font1.setFamily("Microsoft YaHei")  # 设置字体
        font1.setBold(True)  # 加粗
        self.img_combo.setFont(font1)
        self.img_combo.activated[str].connect(self.select_img)

        # 设置照片添加按钮
        self.add_btn_1 = QPushButton(self)
        self.add_btn_1.setGeometry(300, 165, 30, 30)
        self.add_btn_1.setStyleSheet("QPushButton{border-image: url(../static/img/添加按钮1.png)}"
                                     "QPushButton:hover{border-image: url(../static/img/添加按钮2.png)}")
        self.add_btn_1.clicked.connect(self.add_image)

        # 设置照片删除按钮
        self.delete_btn_1 = QPushButton(self)
        self.delete_btn_1.setGeometry(350, 165, 30, 30)
        self.delete_btn_1.setStyleSheet("QPushButton{border-image: url(../static/img/删除按钮1.png)}"
                                        "QPushButton:hover{border-image: url(../static/img/删除按钮2.png)}")
        self.delete_btn_1.clicked.connect(self.delete_img)

        # 照片展示
        pix = QPixmap('../static/img/添加图片提示.png')  # 取图
        x, y, w, h = get_img_x_y(pix.width(), pix.height())
        self.img_label = QLabel(self)
        self.img_label.setGeometry(x, y - 22, w, h)
        self.img_label.setPixmap(pix)  # 把图片放入label
        self.img_label.setScaledContents(True)  # 自适应QLabel大小

        # 照片查看
        self.check_btn = QPushButton(self)
        self.check_btn.setGeometry(x + w - 35, y, 35, 35)
        self.check_btn.setStyleSheet("QPushButton{border-image: url(../static/img/查看1.png)}"
                                     "QPushButton:hover{border-image: url(../static/img/查看2.png)}")
        self.check_btn.clicked.connect(self.check_img)
        self.check_btn.hide()

    # 设置视频处理
    def video_bar(self):

        # 图片下拉框
        self.video_combo = QComboBox(self)
        self.video_combo.setGeometry(300, 285, 115, 35)
        font1 = QFont()  # 创建一个格式对象
        font1.setPixelSize(RATIO(15))  # 设置字体大小
        font1.setFamily("Microsoft YaHei")  # 设置字体
        font1.setBold(True)  # 加粗
        self.video_combo.setFont(font1)
        self.video_combo.activated[str].connect(self.select_video)

        # 设置视频添加按钮
        self.video_add_btn = QPushButton(self)
        self.video_add_btn.setGeometry(300, 330, 30, 30)
        self.video_add_btn.setStyleSheet("QPushButton{border-image: url(../static/img/添加按钮1.png)}"
                                         "QPushButton:hover{border-image: url(../static/img/添加按钮2.png)}")
        self.video_add_btn.clicked.connect(self.add_video)

        # 设置视频删除按钮
        self.video_delete_btn = QPushButton(self)
        self.video_delete_btn.setGeometry(350, 330, 30, 30)
        self.video_delete_btn.setStyleSheet("QPushButton{border-image: url(../static/img/删除按钮1.png)}"
                                            "QPushButton:hover{border-image: url(../static/img/删除按钮2.png)}")
        self.video_delete_btn.clicked.connect(self.delete_video)

        pix = QPixmap('../static/img/添加视频提示.png')  # 取图
        x, y, w, h = get_img_x_y_videos(pix.width(), pix.height())
        self.video_label = QLabel(self)
        self.video_label.setGeometry(x, y, w, h)
        self.video_label.setPixmap(pix)  # 把图片放入label
        self.video_label.setScaledContents(True)  # 自适应QLabel大小

        # 视频查看
        self.play_btn = QPushButton(self)
        self.play_btn.setGeometry(x + w - 35, y, 35, 35)
        self.play_btn.setStyleSheet("QPushButton{border-image: url(../static/img/播放1.png)}"
                                    "QPushButton:hover{border-image: url(../static/img/播放2.png)}")
        self.play_btn.clicked.connect(self.play_video)
        self.play_btn.hide()

    # 当不设置提醒的时候不出现重复
    def set_re_1(self, s):
        if s == "无":
            self.re_label.hide()
            self.re_combo.hide()
            self.btn_set.hide()
        else:
            self.re_label.show()
            self.re_combo.show()
            self.set_re_2(self.re_combo.currentText())

    # 不重复时不出现设置按钮
    def set_re_2(self, s):
        if s == "无":
            self.btn_set.hide()
        else:
            self.btn_set.show()

    # 打开重复设置界面
    def open_re_window(self):
        if self.remind_msg.split(",")[1] == "每天":
            self.open_re_window_signal.emit(get_position_state(self, "1"))
        else:
            self.open_re_window_signal.emit(get_position_state(self, "2"))

    # 添加照片
    def add_image(self):
        # 取图地址
        image_file, _ = QFileDialog.getOpenFileName(self, 'Open file', 'C:\\', 'Image files (*.jpg *.gif *.png *.jpeg)')
        if image_file == "":
            return
        self.images_address_dict.update({image_file.split("/")[-1]: image_file})
        self.img_combo.addItem(image_file.split("/")[-1])
        self.img_combo.setCurrentIndex(self.img_combo.count() - 1)  # 添加后跳到最后一个

        pix = QPixmap(image_file)  # 取图
        x, y, w, h = get_img_x_y(pix.width(), pix.height())
        self.img_label.setGeometry(x, y, w, h)
        self.img_label.setPixmap(pix)  # 把图片放入label
        self.img_label.setScaledContents(True)  # 自适应QLabel大小

        self.check_btn.move(x + w - 35, y)
        self.check_btn.show()

    # 添加视频
    def add_video(self):
        # 取图地址
        video_file, _ = QFileDialog.getOpenFileName(self, 'Open file', 'C:\\', 'Image files (*.mp4 *.flv *.mov *.mkv)')
        if video_file == "":
            return
        self.video_address_dict.update({video_file.split("/")[-1]: video_file})
        self.video_combo.addItem(video_file.split("/")[-1])
        self.video_combo.setCurrentIndex(self.video_combo.count() - 1)  # 添加后跳到最后一个

        pix = QPixmap(get_video_pic(video_file))  # 取图
        x, y, w, h = get_img_x_y_videos(pix.width(), pix.height())
        self.video_label.setGeometry(x, y, w, h)
        self.video_label.setPixmap(pix)  # 把图片放入label
        self.video_label.setScaledContents(True)  # 自适应QLabel大小

        self.play_btn.move(x + w - 35, y)
        self.play_btn.show()

    # 保存
    def save(self):
        if self.title == "":
            msg_box = QMessageBox(QMessageBox.Information, '提示', '请输入标题哦！！')
            font1 = QFont()  # 创建一个格式对象
            font1.setPixelSize(RATIO(20))  # 设置字体大小
            font1.setFamily("Microsoft YaHei")  # 设置字体
            msg_box.setFont(font1)
            msg_box.exec_()
            return

        schedule_event = event_object(self.id)
        schedule_event.title = self.title
        schedule_event.start_time = self.start_time
        schedule_event.end_time = self.end_time
        schedule_event.event_type = self.event_type
        schedule_event.content = self.content
        schedule_event.images = self.images
        schedule_event.videos = self.videos
        schedule_event.remind_msg = self.remind_msg
        schedule_event.save_event()
        for path in self.delect_img_list:
            os.remove(path)

        self.update_signal.emit("")
        if self.is_new_event:
            self.id = "s_" + str(read_setting("事件数"))
            self.is_new_event = False
        self.save_img()
        self.save_video()
        msg_box = QMessageBox(QMessageBox.Information, '提示', '保存成功！')
        font1 = QFont()  # 创建一个格式对象
        font1.setPixelSize(RATIO(20))  # 设置字体大小
        font1.setFamily("Microsoft YaHei")  # 设置字体
        msg_box.setFont(font1)
        msg_box.exec_()

    # 保存-保存图片
    def save_img(self):
        for name, address in self.images_address_dict.items():
            with open(address, 'rb') as f:
                img = f.read()

            if os.path.exists('../event/images/%s' % self.id):
                with open('../event/images/%s/%s' % (self.id, name), 'wb') as f2:
                    f2.write(img)
            else:
                os.makedirs('../event/images/%s' % self.id)
                with open('../event/images/%s/%s' % (self.id, name), 'wb') as f2:
                    f2.write(img)

    # 保存-保存视频
    def save_video(self):
        for name, address in self.video_address_dict.items():
            with open(address, 'rb') as f:
                video = f.read()
            if os.path.exists('../event/videos/%s' % self.id):
                with open('../event/videos/%s/%s' % (self.id, name), 'wb') as f2:
                    f2.write(video)
            else:
                os.makedirs('../event/videos/%s' % self.id)
                with open('../event/videos/%s/%s' % (self.id, name), 'wb') as f2:
                    f2.write(video)

    # 查看图片
    def check_img(self):
        if len(self.images_address_dict) > 0:
            self.check_img_signal.emit(self.images_address_dict[self.img_combo.currentText()])

    # 播放视频
    def play_video(self):
        if len(self.video_address_dict) > 0:
            self.play_video_signal.emit(self.video_address_dict[self.video_combo.currentText()])

    # 删除事件
    def delete(self):

        if self.is_new_event:
            self.close()
        else:
            remind_box = QMessageBox.question(self, '事件删除', '你确定要删除吗?', QMessageBox.Yes | QMessageBox.No,
                                              QMessageBox.No)  # "退出"代表的是弹出框的标题,"你确认退出.."表示弹出框的内容
            if remind_box == QMessageBox.Yes:
                pass
            else:
                return

            try:
                shutil.rmtree("../event/images/%s" % self.id)
            except:
                pass
            try:
                shutil.rmtree("../event/videos/%s" % self.id)
            except:
                pass
            with open('../event/event.json', 'rb') as f:  # 使用只读模型，并定义名称为f
                params = json.load(f)  # 加载json文件
                params.pop(self.id)
            with open('../event/event.json', 'w') as f1:  # 使用只读模型，并定义名称为f
                f1.write(json.dumps(params))
            self.update_signal.emit("")
            self.close()

    """修改事件"""

    # 删除图片
    def delete_img(self):
        if self.img_combo.count() > 0:
            name = self.img_combo.currentText()
            if os.path.exists('../event/images/%s/%s' % (self.id, self.images_address_dict[name].split("/")[-1])):
                self.delect_img_list.append(
                    '../event/images/%s/%s' % (self.id, self.images_address_dict[name].split("/")[-1]))
            self.images_address_dict.pop(name)

            self.img_combo.removeItem(self.img_combo.currentIndex())
            if self.img_combo.count() > 0:
                self.select_img(self.img_combo.currentText())
            else:
                pix = QPixmap('../static/img/添加图片提示.png')  # 取图
                x, y, w, h = get_img_x_y(pix.width(), pix.height())
                self.img_label.setGeometry(x, y - 22, w, h)
                self.img_label.setPixmap(pix)  # 把图片放入label
                self.img_label.setScaledContents(True)  # 自适应QLabel大小
                self.check_btn.move(x + w - 35, y)
                self.check_btn.hide()

    # 删除视频
    def delete_video(self):
        if self.video_combo.count() > 0:
            name = self.video_combo.currentText()
            if os.path.exists('../event/videos/%s/%s' % (self.id, self.video_address_dict[name].split("/")[-1])):
                self.delect_img_list.append(
                    '../event/videos/%s/%s' % (self.id, self.video_address_dict[name].split("/")[-1]))
            self.video_address_dict.pop(name)

            self.video_combo.removeItem(self.video_combo.currentIndex())
            if self.video_combo.count() > 0:
                self.select_video(self.video_combo.currentText())
            else:
                pix = QPixmap('../static/img/添加视频提示.png')  # 取图
                x, y, w, h = get_img_x_y_videos(pix.width(), pix.height())
                self.video_label.setGeometry(x, y - 22, w, h)
                self.video_label.setPixmap(pix)  # 把图片放入label
                self.video_label.setScaledContents(True)  # 自适应QLabel大小
                self.play_btn.move(x + w - 35, y)
                self.play_btn.hide()

    # 选择照片
    def select_img(self, s):
        pix = QPixmap(self.images_address_dict[s])  # 取图
        x, y, w, h = get_img_x_y(pix.width(), pix.height())
        self.img_label.setGeometry(x, y, w, h)
        self.img_label.setPixmap(pix)  # 把图片放入label
        self.img_label.setScaledContents(True)  # 自适应QLabel大小
        self.check_btn.move(x + w - 35, y)

    # 选择视频
    def select_video(self, s):
        pix = QPixmap(get_video_pic(self.video_address_dict[s]))  # 取图
        x, y, w, h = get_img_x_y_videos(pix.width(), pix.height())
        self.video_label.setGeometry(x, y, w, h)
        self.video_label.setPixmap(pix)  # 把图片放入label
        self.video_label.setScaledContents(True)  # 自适应QLabel大小
        self.play_btn.move(x + w - 35, y)

    # 内容发生变化修改内容属性
    def content_change(self):
        self.content = self.content_edit.toPlainText()

    # 每周和每日设置调节
    def set_re_msg(self):
        # 重复信息
        self.remind_msg = self.time_combo.currentText() + "," + self.re_combo.currentText() + "," + self.re_time + "," + self.re_week

    # 当类型下拉框选项改变时修改状态
    def type_action(self, s):
        self.type_label.setText(s)
        self.event_type = self.type_label.text()

    # 事件标题发生改变时修改
    def title_edit_change(self):
        self.title = self.title_edit.text()

    # 开始时间发生修改时修改
    def start_time_change(self):
        self.dateEdit2.setMinimumDateTime(self.dateEdit1.dateTime())
        # 事件开始时间
        self.start_time = str(self.dateEdit1.date().getDate()[0]) + "," + str(
            self.dateEdit1.date().getDate()[1]) + "," + str(self.dateEdit1.date().getDate()[2]) + "," + \
                          str(self.dateEdit1.dateTime().time().hour()) + "," + str(
            self.dateEdit1.dateTime().time().minute())

    # 结束时间发生修改时修改
    def end_time_change(self):
        self.dateEdit1.setMaximumDateTime(self.dateEdit2.dateTime())
        # 事件结束时间
        self.end_time = str(self.dateEdit2.date().getDate()[0]) + "," + str(
            self.dateEdit2.date().getDate()[1]) + "," + str(self.dateEdit2.date().getDate()[2]) + "," + \
                        str(self.dateEdit2.dateTime().time().hour()) + "," + str(
            self.dateEdit2.dateTime().time().minute())

    # 修改每天重复提醒时间
    def change_re_time(self, s):
        self.re_time = s
        self.set_re_msg()

    # 修改重复周期
    def change_re_week(self, s):
        self.re_week = s
        self.set_re_msg()

    # 修改重复时间
    def change_thread_re_time(self):
        self.thread.re_time = self.re_time

    # 修改重复周期
    def change_thread_re_week(self):
        self.thread.re_week = self.re_week

    """去除工具栏后重写点击移动函数"""

    def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton:
            self.close_window_signal.emit("")
            self.m_flag = True
            self.m_Position = event.globalPos() - self.pos()  # 获取鼠标相对窗口的位置
            event.accept()

    def mouseMoveEvent(self, QMouseEvent):
        try:
            if Qt.LeftButton and self.m_flag:
                self.move(QMouseEvent.globalPos() - self.m_Position)  # 更改窗口位置
                QMouseEvent.accept()
        except Exception:
            pass

    def mouseReleaseEvent(self, QMouseEvent):
        self.m_flag = False
        self.setCursor(QCursor(Qt.ArrowCursor))

    def closeEvent(self, event):
        self.thread.w_re_1.close()
        self.thread.w_re_2.close()
        self.close()


# 提醒窗口
class remind_window(QWidget):
    # 创建自定义信号
    open_re_window_signal = pyqtSignal(str)  # 打开重复设置窗口信号
    close_window_signal = pyqtSignal(str)  # 点击主窗口关闭其他子窗口
    check_img_signal = pyqtSignal(str)
    play_video_signal = pyqtSignal(str)
    update_signal = pyqtSignal(str)

    def __init__(self, id="s_0"):
        super().__init__()
        self.id = id
        self.is_festival = False
        if self.id != "festival":
            with open('../event/event.json', 'rb') as f:  # 使用只读模型，并定义名称为f
                params = json.load(f)  # 加载json文件
            self.type = params[self.id]["event_type"]
            self.title = params[self.id]["title"]
        else:
            self.type = "🎉"
            self.title = "节日快乐！！"
            self.is_festival = True

        self.init_ui()

    """初始化函数"""

    # 初始化ui函数
    def init_ui(self):
        self.resize(300, 150)  # 设置窗口大小
        self.setFixedSize(300, 150)  # 固定大小
        self.setObjectName("MainWindow")
        # self.setStyleSheet("#MainWindow{background-color:white}")
        self.setWindowFlags(Qt.FramelessWindowHint)  # 去边框化
        self.setWindowIcon(QIcon("../static/img/logo1.png"))

        ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID("myappid")
        self.set_background()
        self.set_event_remind()

    def set_background(self):
        # 设置背景函数
        pix = QPixmap('../static/img/提醒灰色外边框.png')  # 取图
        self.background = QLabel(self)
        self.background.setGeometry(0, 0, 300, 150)

        self.background.setPixmap(pix)  # 把图片放入label

    def set_event_remind(self):
        # 提示标签
        self.type_label = QLabel(self.type + " " + self.title, self)
        self.type_label.setGeometry(10, 30, 280, 50)
        font1 = QFont()  # 创建一个格式对象
        font1.setPixelSize(RATIO(35))  # 设置字体大小
        font1.setFamily("Microsoft YaHei")  # 设置字体
        font1.setBold(True)  # 加粗
        self.type_label.setAlignment(Qt.AlignCenter)
        self.type_label.setFont(font1)  # 将lb1设置font1格式

        # 设置查看按钮
        self.check_btn = QPushButton("查看", self)
        self.check_btn.setGeometry(30, 100, 105, 30)
        font2 = QFont()  # 创建一个格式对象
        font2.setPixelSize(15)  # 设置字体大小
        font2.setFamily("Microsoft YaHei")  # 设置字体
        self.check_btn.setFont(font2)
        self.check_btn.clicked.connect(self.open_schedule_window)

        # 设置确定按钮
        self.ok_btn = QPushButton("确定", self)
        self.ok_btn.setGeometry(165, 100, 105, 30)
        font3 = QFont()  # 创建一个格式对象
        font3.setPixelSize(15)  # 设置字体大小
        font3.setFamily("Microsoft YaHei")  # 设置字体
        self.ok_btn.setFont(font3)
        self.ok_btn.clicked.connect(self.close)

    def open_schedule_window(self):
        self.s_w = Schedule_msg_window(self.id)
        self.s_w.show()
        self.close()

    """去除工具栏后重写点击移动函数"""

    def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton:
            self.close_window_signal.emit("")
            self.m_flag = True
            self.m_Position = event.globalPos() - self.pos()  # 获取鼠标相对窗口的位置
            event.accept()

    def mouseMoveEvent(self, QMouseEvent):
        try:
            if Qt.LeftButton and self.m_flag:
                self.move(QMouseEvent.globalPos() - self.m_Position)  # 更改窗口位置
                QMouseEvent.accept()
        except Exception:
            pass

    def mouseReleaseEvent(self, QMouseEvent):
        self.m_flag = False
        self.setCursor(QCursor(Qt.ArrowCursor))


# 搜索列表外框
class search_list_frame(QWidget):
    open_event_window_signal = pyqtSignal(str)

    def __init__(self, key):
        super().__init__()
        self.key = key
        self.event_list = search_event(key)
        self.init_ui()

    # 初始化ui函数
    def init_ui(self):
        self.resize(300, 250)  # 设置窗口大小
        self.setFixedSize(300, 250)  # 固定大小
        self.setWindowFlags(Qt.FramelessWindowHint)  # 去边框化
        self.setWindowIcon(QIcon("../static/img/logo1.png"))

        ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID("myappid")
        self.set_frame()

        # 设置关闭按钮
        btn_close = QPushButton(self)
        btn_close.setGeometry(272, 2, 26, 26)
        btn_close.setStyleSheet("QPushButton{border-image: url(../static/img/关闭.png)}"
                                "QPushButton:hover{border-image: url(../static/img/关闭2.png)}")
        btn_close.clicked.connect(self.close)

        if len(self.event_list) > 0 and self.key != "":
            self.set_event_window()
        else:
            if self.key != "":
                # 查询结果标签
                titel_label = QLabel("未找到相关的事件", self)
                titel_label.setGeometry(0, 50, 300, 90)
                font1 = QFont()  # 创建一个格式对象
                font1.setPixelSize(RATIO(33))  # 设置字体大小
                font1.setFamily("Microsoft YaHei")  # 设置字体
                titel_label.setAlignment(Qt.AlignCenter)
                titel_label.setFont(font1)  # 将lb1设置font1格式

                # 查询结果标签
                titel_label = QLabel("  试着换一个关键字吧！", self)
                titel_label.setGeometry(0, 100, 300, 90)
                font1 = QFont()  # 创建一个格式对象
                font1.setPixelSize(RATIO(25))  # 设置字体大小
                font1.setFamily("Microsoft YaHei")  # 设置字体
                titel_label.setAlignment(Qt.AlignCenter)
                titel_label.setFont(font1)  # 将lb1设置font1格式
            else:
                # 查询结果标签
                titel_label = QLabel("    没有输入哦！！", self)
                titel_label.setGeometry(0, 50, 300, 90)
                font1 = QFont()  # 创建一个格式对象
                font1.setPixelSize(RATIO(33))  # 设置字体大小
                font1.setFamily("Microsoft YaHei")  # 设置字体
                titel_label.setAlignment(Qt.AlignCenter)
                titel_label.setFont(font1)  # 将lb1设置font1格式

                # 查询结果标签
                titel_label = QLabel("  试着输入一个关键字吧！", self)
                titel_label.setGeometry(0, 100, 300, 90)
                font1 = QFont()  # 创建一个格式对象
                font1.setPixelSize(RATIO(25))  # 设置字体大小
                font1.setFamily("Microsoft YaHei")  # 设置字体
                titel_label.setAlignment(Qt.AlignCenter)
                titel_label.setFont(font1)  # 将lb1设置font1格式

    def set_event_window(self):
        # 查询结果标签
        titel_label = QLabel("相关事件：", self)
        titel_label.setGeometry(105, 0, 120, 30)
        font1 = QFont()  # 创建一个格式对象
        font1.setPixelSize(RATIO(23))  # 设置字体大小
        font1.setFamily("Microsoft YaHei")  # 设置字体
        titel_label.setAlignment(Qt.AlignCenter)
        titel_label.setFont(font1)  # 将lb1设置font1格式

        scroll = QScrollArea(self)
        scroll.setGeometry(2, 30, 296, 205)
        scroll.setFixedSize(296, 205)
        self.e_window = search_list(self.event_list)
        self.e_window.open_event_singal.connect(self.open_event)
        scroll.setWidget(self.e_window)
        scroll.setFrameShape(QFrame.NoFrame)
        scroll.setStyleSheet("QScrollArea {background-color:transparent;}")
        scroll.viewport().setStyleSheet("background-color:transparent;")
        scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        # scroll.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)

    def set_frame(self):
        pix = QPixmap('../static/img/查询日程边框.png')  # 取图
        frame = QLabel(self)
        frame.setGeometry(0, 0, 300, 250)
        frame.setPixmap(pix)  # 把图片放入label

    # 发送打开信号
    def open_event(self, s):
        self.open_event_window_signal.emit(s)

    """去除工具栏后重写点击移动函数"""

    def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton:
            self.m_flag = True
            self.m_Position = event.globalPos() - self.pos()  # 获取鼠标相对窗口的位置
            event.accept()

    def mouseMoveEvent(self, QMouseEvent):
        try:
            if Qt.LeftButton and self.m_flag:
                self.move(QMouseEvent.globalPos() - self.m_Position)  # 更改窗口位置
                QMouseEvent.accept()
        except Exception:
            pass

    def mouseReleaseEvent(self, QMouseEvent):
        self.m_flag = False
        self.setCursor(QCursor(Qt.ArrowCursor))


# 搜索列表
class search_list(QWidget):
    open_event_singal = pyqtSignal(str)

    def __init__(self, event_list):
        super().__init__()
        self.event_list = event_list
        self.btn_list = []
        self.init_ui()

    # 初始化ui函数
    def init_ui(self):
        h = len(self.event_list) * 190
        self.resize(296, h)  # 设置窗口大小
        self.setFixedSize(296, h)  # 固定大小
        self.setStyleSheet("#MainWindow{background-color:white}")
        self.setWindowFlags(Qt.FramelessWindowHint)  # 去边框化
        # self.setAttribute(Qt.WA_TranslucentBackground)  # 设置窗口背景透明

        self.set_event()

    # 设置事件
    def set_event(self):
        with open("../event/event.json", "r") as f:
            events = json.load(f)
        count = 0
        for i in self.event_list:
            # 设置背景函数
            pix = QPixmap('../static/img/查询日程框架.png')  # 取图
            frame = QLabel(self)
            frame.setGeometry(23, count * 190, 250, 184)
            frame.setPixmap(pix)  # 把图片放入label

            if len(events[i]["title"]) > 5:
                name = events[i]["event_type"] + " " + events[i]["title"][0:5] + ".."
            else:
                name = events[i]["event_type"] + " " + events[i]["title"]

            # 标题
            titel_label = QLabel(name, self)
            titel_label.setGeometry(23, count * 190, 250, 40)
            font1 = QFont()  # 创建一个格式对象
            font1.setPixelSize(RATIO(27))  # 设置字体大小
            font1.setFamily("Microsoft YaHei")  # 设置字体
            titel_label.setAlignment(Qt.AlignCenter)
            titel_label.setFont(font1)  # 将lb1设置font1格式

            start_time = " 开始: " + events[i]["start_time"].split(",")[0] + "年" + events[i]["start_time"].split(",")[
                1] + "月" + \
                         events[i]["start_time"].split(",")[2] + "日"

            # 开始时间
            start_time_label = QLabel(start_time, self)
            start_time_label.setGeometry(27, 35 + count * 190, 250, 40)
            font2 = QFont()  # 创建一个格式对象
            font2.setPixelSize(RATIO(16))  # 设置字体大小
            font2.setFamily("Microsoft YaHei")  # 设置字体

            start_time_label.setFont(font2)  # 将lb1设置font1格式

            end_time = " 结束: " + events[i]["end_time"].split(",")[0] + "年" + events[i]["end_time"].split(",")[1] + "月" + \
                       events[i]["end_time"].split(",")[2] + "日"

            # 结束时间
            end_time_label = QLabel(end_time, self)
            end_time_label.setGeometry(27, 70 + count * 190, 250, 40)
            font3 = QFont()  # 创建一个格式对象
            font3.setPixelSize(RATIO(16))  # 设置字体大小
            font3.setFamily("Microsoft YaHei")  # 设置字体

            end_time_label.setFont(font3)  # 将lb1设置font1格式

            # 内容文本
            if events[i]["content"] != "":
                content = events[i]["content"]
            else:
                content = "该事件没有具体内容....."

            content_label = QTextEdit(content, self)
            content_label.setGeometry(25, 111 + count * 190, 246, 69)
            font4 = QFont()  # 创建一个格式对象
            font4.setPixelSize(RATIO(15))  # 设置字体大小
            font4.setFamily("Microsoft YaHei")  # 设置字体
            content_label.setFont(font4)
            content_label.setFocusPolicy(Qt.NoFocus)

            btn = QPushButton(self)
            btn.setGeometry(202, 42 + count * 190, 68, 68)
            btn.setStyleSheet("QPushButton{border-image: url(../static/img/查看1.png)}"
                              "QPushButton:hover{border-image: url(../static/img/查看2.png)}")
            self.btn_list.append(btn)
            self.btn_list[count].text()
            self.btn_list[count].clicked.connect(lambda: self.open_event(self.sender().y()))
            count = count + 1

    def open_event(self, s):
        self.open_event_singal.emit(self.event_list[int((int(s)) / 190)])


if __name__ == '__main__':
    app = QApplication(sys.argv)

    w_1 = Schedule_msg_window()
    w_1.show()

    app.exec()
